package bbsmsg.util;

import java.io.IOException;
import java.io.Reader;

import org.apache.ibatis.io.Resources;
import org.apache.ibatis.session.SqlSession;
import org.apache.ibatis.session.SqlSessionFactory;
import org.apache.ibatis.session.SqlSessionFactoryBuilder;

public class MybatisUtil {
	private static final String RESOURCE="msg-config.xml";
	public static SqlSessionFactory getSqlSessionFactory() {
		Reader reader=null;
		try {
			reader=Resources.getResourceAsReader(RESOURCE);
			SqlSessionFactory sql=new SqlSessionFactoryBuilder().build(reader);
			return sql;
		} catch (Exception e) {
			e.printStackTrace();
		}
		return null;
	}
	public static SqlSession getSqlSession() {
		SqlSession session=getSqlSessionFactory().openSession();
		return session;
	}
	public static void closeSession() {
		SqlSession session=getSqlSessionFactory().openSession();
		if (session!=null) {
			session.close();
		}
	}
}
